package xushuo.dao.entity.weixin.user;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;

/**
 * Create by zhangpe0312@qq.com on 2018/2/2.
 * <p>
 * 通过微信小程序获取的用户信息
 * <p>
 * userInfo参数说明：
 * <p>
 * 参数	类型	说明
 * nickName	String	用户昵称
 * avatarUrl	String	用户头像，最后一个数值代表正方形头像大小（有0、46、64、96、132数值可选，0代表640*640正方形头像），用户没有头像时该项为空。若用户更换头像，原有头像URL将失效。
 * gender	String	用户的性别，值为1时是男性，值为2时是女性，值为0时是未知
 * city	String	用户所在城市
 * province	String	用户所在省份
 * country	String	用户所在国家
 * language	String	用户的语言，简体中文为zh_CN
 */
@Entity
@Table(name = "GetUserInfo")
public class GetUserInfo implements GetInfo {

    private String id;
    private String nickName;
    private String avatarUrl;
    private int gender;
    private String city;
    private String province;
    private String country;
    private String language;


    //信息创建时间
    private Date getTime;
    //维护这些信息的表 - UserLoginInfo 的属性为 userInfo
    private UserLoginInfo userLoginInfo;

    private GetUserInfo() {
    }

    @Id
    @Column(name = "id", nullable = false, unique = true)
    @GenericGenerator(name = "generator", strategy = "uuid")
    @GeneratedValue(generator = "generator")
    public String getId() {
        return id;
    }

    @Column(name = "getTime", updatable = false, length = 19)
    @Temporal(TemporalType.TIMESTAMP)
    public Date getGetTime() {
        return getTime;
    }

    @Column(name = "nickName", nullable = false, length = 32)
    public String getNickName() {
        return nickName;
    }

    /**
     * 微信头像地址是唯一的，固作为唯一标识
     *
     * @return 微信用户的头像地址
     */
    @Column(name = "avatarUrl", nullable = false, length = 200, unique = true)
    public String getAvatarUrl() {
        return avatarUrl;
    }

    @Column(name = "gender", nullable = false, length = 32)
    public int getGender() {
        return gender;
    }

    @Column(name = "city", nullable = false, length = 32)
    public String getCity() {
        return city;
    }

    @Column(name = "province", nullable = false, length = 32)
    public String getProvince() {
        return province;
    }

    @Column(name = "country", nullable = false, length = 32)
    public String getCountry() {
        return country;
    }

    @Column(name = "language", nullable = false, length = 32)
    public String getLanguage() {
        return language;
    }

    //关联表UserLoginInfo 为维护这个信息的对象
    @OneToOne(mappedBy = "userInfo")
    public UserLoginInfo getUserLoginInfo() {
        return userLoginInfo;
    }


    public static class Builder {

        GetUserInfo userInfo = new GetUserInfo();

        public Builder setNickName(String nickName) {
            userInfo.setNickName(nickName);
            return this;
        }

        public Builder setGetTime() {
            userInfo.setGetTime(new Date());
            return this;
        }

        public Builder setAvatarUrl(String avatarUrl) {
            userInfo.setAvatarUrl(avatarUrl);
            return this;
        }

        public Builder setUserLoginInfo(UserLoginInfo userLoginInfo) {
            userInfo.setUserLoginInfo(userLoginInfo);
            return this;
        }

        public Builder setGender(int gender) {
            userInfo.setGender(gender);
            return this;
        }

        public Builder setCity(String city) {
            userInfo.setCity(city);
            return this;
        }

        public Builder setProvince(String province) {
            userInfo.setProvince(province);
            return this;
        }

        public Builder setCountry(String country) {
            userInfo.setCountry(country);
            return this;
        }

        public Builder setLanguage(String language) {
            userInfo.setLanguage(language);
            return this;
        }

        public Builder setId(String id) {
            userInfo.setId(id);
            return this;
        }

        public GetUserInfo keep() {
            return userInfo;
        }

    }

    public void setId(String id) {
        this.id = id;
    }

    public void setUserLoginInfo(UserLoginInfo userLoginInfo) { this.userLoginInfo = userLoginInfo; }

    public void setGetTime(Date getTime) {
        this.getTime = getTime;
    }


    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public void setGender(int gender) {
        this.gender = gender;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public void setLanguage(String language) {
        this.language = language;
    }


}
